#!/usr/bin/env node
// 循环录入用户信息
// cli
// 请输入用户名 请输入手机 请输入邮箱  是否继续录入

const commander = require('commander')
const inquirer = require('inquirer')
const fs = require('fs')
const action = [
    {
        type: "input",
        message: "请输入名称",
        name: "name"
    },
    {
        type: "input",
        message: "请输入手机号",
        name: "phone"
    },
    {
        type: "input",
        message: "请输入邮箱",
        name: "email"
    },
    {
        type: "confirm",
        message: "是否继续录入",
        name: "bool"
    }
]
let userList = [];
commander.command('input').action(() => {
    // 执行输入操作
    inputUser()
})
function inputUser() {
    inquirer.prompt(action).then(res=>{
        userList.push(res)
        if(res.bool) {
            inputUser()
        }else {
            fs.writeFileSync('userData.json',JSON.stringify(userList))
        }
    })
}

commander.parse(process.argv)